#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<algorithm>
using namespace std;
using pii = pair<int, int>;
const int N = 1010;
int a[N], b[N], ed[N], sum[N];
struct srt
{
    int x, y;
    int id;
}c[N], d[N];
int n;
bool cmp1(srt& a, srt& b)
{
    return a.x < b.x;
}
bool cmp2(srt& a, srt& b)
{
    return a.y > b.y;
}
int main()
{
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i];
    for (int i = 1; i <= n; i++) cin >> b[i];
    int clen = 0, dlen = 0;
    for (int i = 1; i <= n; i++)
    {
        if (a[i] < b[i]) c[clen++] = { a[i],b[i],i };
        else d[dlen++] = { a[i],b[i],i };
    }
    sort(c, c + clen, cmp1);
    sort(d, d + dlen, cmp2);
    for (int i = clen, j = 0; j < dlen; i++, j++) c[i] = d[j];
    sum[0] = c[0].x;
    for (int i = 1; i <= clen + dlen; i++)
    {
        sum[i] = sum[i - 1] + c[i].x;
        ed[i] = max(ed[i - 1], sum[i - 1]) + c[i - 1].y;
    }
    cout << ed[clen + dlen] << endl;
    for (int i = 0; i < clen + dlen; i++) cout << c[i].id << " ";
}